<template>
  <div>
    <constView ref="costView" v-if="modalDisplay" @handleButon="handleButon" v-bind="configs"></constView>
    <a-button @click="change">{{ test }}</a-button>
    <popup ref="popupModal" @close="modalClose" v-bind="addModalData"></popup>
  </div>

</template>
<script>
import constView from '@/components/cn-components/ViewModals'
import popup from '@/components/view/base-crud/form/FormAddEdit'

export default {
  name: 'discountBudget',
  description:'货补费用明细',
  components: {
    constView,
    popup
  },
  data() {
    return {
      // 列表主数据
      test: 0,
      modalDisplay: true,
      config: {
        list: [
          {
            type: 'input',
            md: 7,
            // label: '费用编号',
            placeholder: '请输入费用编号',
            name: 'poolCode'
          },
          {
            type: 'input',
            md: 7,
            // label: '商品编号',
            placeholder: '请输入商品编号',
            name: 'productCode'
          },
          {
            type: 'input',
            md: 7,
            // label: '商品名称',
            placeholder: '请输入商品名称',
            name: 'productName'
          },
          {
            type: 'input',
            md: 7,
            // label: '经销商编号',
            placeholder: '请输入经销商编号',
            name: 'custCode'
          },
          {
            type: 'input',
            md: 7,
            // label: '经销商名称',
            placeholder: '请输入经销商名称',
            name: 'custName'
          },
          // {
          //   toggleModal: [
          //
          //   ]
          // }

        ]

      },
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '费用凭证编号',
          align: 'left',
          dataIndex: 'poolCode'
        },
        {
          title: '经销商名称',
          align: 'left',
          dataIndex: 'custName'
        },
        {
          title: '经销商编号',
          align: 'left',
          dataIndex: 'custCode',
          scopedSlots: { customRender: 'custCode' }
        },
        // {
        //   title: '费用类型',
        //   align: 'left',
        //   dataIndex: 'type'
        // },
        {
          title: '科目编号',
          align: 'left',
          dataIndex: 'subjectCode'
        },
        {
          title: '科目名称',
          align: 'left',
          dataIndex: 'subjectName'
        },
        {
          title: '商品编号',
          align: 'left',
          dataIndex: 'productCode'
        },
        {
          title: '商品名称',
          align: 'left',
          dataIndex: 'productName'
        },
        {
          title: '费用池总额',
          align: 'left',
          dataIndex: 'totalFee'
        },
        {
          title: '已使用金额',
          align: 'left',
          dataIndex: 'usedFee'
        },
        {
          title: '费用池余额',
          align: 'left',
          dataIndex: 'balance'
        },
        {
          title: '占用金额',
          align: 'left',
          dataIndex: 'frozenFee'
        },

        {
          title: '操作',
          dataIndex: 'action',
          fixed: 'right',
          align: 'center',
          width: 150,
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            // filterIcon: 'filterIcon',
            customRender: 'action'
          }
        }
      ],
      url: {
        list: window._CONFIG['domianDmsURL'] + '/dmsFeePoolController/findPageList',
        detail: window._CONFIG['domianDmsURL'] + '/dmsFeePoolController/getInfo',
        delete: window._CONFIG['domianDmsURL'] + '/dmsFeePoolController/deleteById'
      },
      // 列表按钮配置
      btns: [false, false, false, false],//1新增，2启用，3停用，4，导出
      // 新增主数据
      modaltitle: '',
      urlAdd: {
        addOrUpdateUrl: window._CONFIG['domianURL'] + '/dmsFeePoolController/saveEntity'
      },
      rowKey: 'custCode',
      addForm: {
        list: [
          // 输入框
          {
            span: 0,
            md: 8,
            label: '门店编号',
            type: 'input',
            placeholder: '请输入',
            name: 'terminalCode',
            check: {
              rules: [{ required: true, message: '请输入门店编号' }]
            }
          },
          {
            span: 0,
            md: 8,
            label: '经销商名称',
            label2: '经销商编号',
            type: 'springFrame',
            placeholder: '请选择',
            name: 'custName',
            code: 'custCode',
            check: {
              rules: [{ required: true, message: '请选择经销商名称' }]
            },
            listurl: window._CONFIG['domianURL'] + '/customerController/getPageList'
          }
        ]
      }

    }
  },
  created() {
    this.creatData()

  },
  methods: {
    change() {
      this.test++
    },
    creatData() {
      this.$nextTick(() => {

        this.$refs.costView.config(this.config)
      })
    },
    // 组件按钮触发函数
    handleButon(btn, data) {
      // 调用新增组件
      if (btn == 'newAdd') {
        this.modaltitle = '费用管理新增'
        this.$refs.popupModal.edit()
      } else if (btn == 'edit') {
        this.modaltitle = '费用管理编辑'
        this.$refs.popupModal.edit()
      } else if (btn == 'detail') {
        this.modaltitle = '费用管理详情'
        this.$refs.popupModal.edit()
      }

    },
    modalClose() {
      this.$refs.costView.loadData1(1)
    }

  },
  computed: {
    // 列表页面数据
    configs() {
      return Object.assign({}, {
        url: this.url,
        columns: this.columns,
        rowKey: this.rowKey,
        btns: this.btns,
        tableActions:false,
      })
    },
    // 新增页面初始化数据
    addModalData() {
      return Object.assign({}, {
        title: this.modaltitle,
        width: '70%',
        config: this.addForm,
        urlAdd: this.urlAdd

      })
    }
  }
}
</script>
<style scoped>

</style>
